package com.kgcx.coupon.controller;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.coupon.domain.Comment;
import com.kgcx.coupon.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhulong
 */
@Api(description = "评价接口", tags = "评价接口")
@RestController
@RequestMapping("comment")
public class CommentController extends BaseController {

    @Autowired
    private CommentService commentService;

    @ApiOperation(value = "用户评价", httpMethod = "POST", notes = "这是用户发起对司机评价的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNo", value = "订单编号", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "driverId", value = "司机ID", required = true, paramType = "query", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "serviceScore", value = "服务满意度评分", required = true, paramType = "query", dataType = "float", dataTypeClass = Float.class),

    })
    @PostMapping("addComment")
    public ReturnData<Integer> addComment(String orderNo, Integer userId, Integer driverId, Float serviceScore) {
        ReturnData<Integer> returnData = ReturnData.getResult();
        List<Comment> list = commentService.selectByOrderNo(orderNo);
        if (list != null && list.size() > 0) {
            returnData.setCode("-1");
            returnData.setMsg("该订单已评价，不能重复评价");
            return returnData;
        }
        Integer one = commentService.addComment(orderNo, userId, driverId, serviceScore);
        returnData.setData(one);
        return returnData;
    }

    /**
     * 专给监管平台提供查询
     */
    @ApiOperation(value = "监管平台查询评价信息", httpMethod = "GET", notes = "这是用来给监管平台查询评价信息的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序,sql格式", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "kid", value = "主键ID", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "userId", value = "用户ID", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "driverId", value = "司机ID", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderNo", value = "订单编号", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("queryCommentWithPage")
    public ReturnData<List<Comment>> queryCommentWithPage() {
        RequestData rd = this.getRequestData();
        List<Comment> commentList = commentService.queryCommentWithPage(rd);
        return new ReturnData<>(commentList);
    }


    @ApiOperation(value = "根据订单号查询", httpMethod = "GET", notes = "这是用来根据查询评价信息的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNo", value = "订单号", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
    })
    @GetMapping("selectByTitle")
    public ReturnData<List<Comment>> selectByOrderNo() {
        RequestData requestData = this.getRequestData();
        List<Comment> commentList = commentService.selectByOrderNo(requestData.getString("orderNo"));
        return new ReturnData<>(commentList);
    }

}
